//
//  BigPosterView.m
//  卢卡的时光网
//
//  Created by 卡神 on 15/7/26.
//  Copyright © 2015年 lok. All rights reserved.
//

#import "BigPosterView.h"


@implementation BigPosterView

- (nonnull instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(nonnull UICollectionViewLayout *)layout {
    if (self = [super initWithFrame:frame collectionViewLayout:layout]) {
        self.delegate = self;
        self.dataSource = self;
        [self registerClass:[BigCell class] forCellWithReuseIdentifier:@"bigCell"];
    }
    return self;
}



#pragma mark -collectionView's create
- (void)collectionView:(nonnull UICollectionView *)collectionView didSelectItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.row != self.currentIndex) {
        [self scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        self.currentIndex = indexPath.row;
    } else {
        BigCell *cell = (BigCell *)[collectionView cellForItemAtIndexPath:indexPath];
        [cell flip];
    }
}

- (UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    BigCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"bigCell" forIndexPath:indexPath];
    cell.movie = self.imageData[indexPath.row];
    return cell;
}


 



@end
